Skip to content

Pin the 401 → refresh → retry path in PPClient._request#4

Merged
ak2k merged 1 commit into
mainfrom
worktree-work-rdus-pp-401-refresh-test
May 15, 2026
Merged

Pin the 401 → refresh → retry path in PPClient._request#4
ak2k merged 1 commit into
mainfrom
worktree-work-rdus-pp-401-refresh-test

Conversation

@ak2k

@ak2k ak2k commented May 15, 2026

Copy link
Copy Markdown
Owner

Summary

Adds three tests against PPClient._request's auth-retry path, driven by httpx.MockTransport + a monkeypatched refresh_tokens. The retry only fires when a token expires mid-session, so it's exercised by chance rather than by design — when it regresses, the failure mode is a cascade (every PP request returns 401, no awards render, callers see "no award found" for the whole session).

Coverage:

  • Happy path — 401 → refresh fires once → retry uses the new access token → 200 surfaces to caller. Asserts the second request's Authorization header carries the refreshed token, not the stale one.
  • Non-401 passthrough — a 500 response passes through unmodified; refresh_tokens must not fire.
  • Double-401 — retry-once semantics: refresh_tokens runs once, only two requests go out (no third), the second 401 surfaces. Guards against an infinite-loop regression.

Pure unit tests, no live API.

Closes work-rdus.

Test plan

  • make check (ruff lint + format + basedpyright strict + pytest) — all green
  • 72/72 tests pass (69 existing + 3 new)
  • Tests use MockTransport + monkeypatch only — no network

The retry only fires when a token expires mid-session, so it's exercised
by chance rather than by design. When it regresses, the failure mode is
a cascade: every PP request returns 401, no awards render, callers see
"no award found" for the entire session.

Three tests, all driven by httpx.MockTransport + a monkeypatched
refresh_tokens:

  1. happy path — 401 → refresh fires once → retry uses the new
     access token → 200 surfaces to caller
  2. non-401 — refresh must NOT fire; response passes through
  3. double-401 — retry-once semantics: refresh runs once, no third
     request, second 401 surfaces (we don't loop forever)

Closes work-rdus.
@ak2k ak2k merged commit 1e7f452 into main May 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant